<?php

// 删除一个商品
// 删除内容保存在回收站内

require $this->website['path']['action'] . '/admin/isedit.php';

$json = array('status' => 'error', 'msg' => '', 'data' => '');

$id = fn_post('id');

if (!$id || !is_numeric($id)) {
	$json['msg'] = '错误编号';
} elseif (!$this->website['class']['db']
		->table('product')
		->where('id=?', $id)
		->limit(1)
		->count()) {
	$json['msg'] = '商品不存在或已删除';
} else {
	$table = [
		array('id' => 'id', 'table' => 'product'),
		array('id' => 'pid', 'table' => 'product_detail'),
		array('id' => 'pid', 'table' => 'product_image'),
	];
	$arr = [];
	foreach ($table as $v) {
		$arr[$v['table']] = $this->website['class']['db']
			->table($v['table'])
			->where($v['id'] . '=' . $id)
			->select();
		$this->website['class']['db']
			->table($v['table'])
			->where($v['id'] . '=' . $id)
			->delete();
	}
	$this->website['class']['db']
		->table('recycle')
		->field('uid', 'createtime', 'cont')
		->value($admin['id'], $_SERVER['REQUEST_TIME'], json_encode($arr, JSON_UNESCAPED_UNICODE))
		->insert();

	$json['status'] = 'ok';
	$json['msg'] = '已放入回收站内';
	// $json['sql'] = $this->website['class']['db']->sql();

}

$this->json_encode($json);
